/*
 * Copyright (c) 2020 - present, Inspur Genersoft Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.inspur.edp.web.npmpackage.api.entity.settings;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * npm 配置
 *
 * @author noah
 */
public class NpmSettings {
    /**
     * 离线模式  默认为true
     */
    private boolean offline = true;

    private String settingMode;
    private NpmSettingConfig settingConfig;


    public boolean isOffline() {
        return offline;
    }

    public void setOffline(boolean offline) {
        this.offline = offline;
    }

    public String getSettingMode() {
        return settingMode;
    }

    public void setSettingMode(String settingMode) {
        this.settingMode = settingMode;
    }

    public NpmSettingConfig getSettingConfig() {
        return settingConfig;
    }

    public void setSettingConfig(NpmSettingConfig settingConfig) {
        this.settingConfig = settingConfig;
    }

    /**
     * 更新当前更新的最后更新时间
     *
     * @param lastUpdated
     */
    public void setLastUpdated(String lastUpdated) {
        List<NpmRepository> filterRepository = Arrays.stream(this.getSettingConfig().getRepositories()).filter(t -> t.getId().equals(this.getSettingMode())).collect(Collectors.toList());
        if (filterRepository != null && filterRepository.size() > 0) {
            filterRepository.forEach(t -> t.setLastUpdated(lastUpdated));
        }
    }
}
